<template>
	<view>
		<view class="myview">
			<p>任务名称：<strong>{{taskInfo.taskName}}</strong></p>
			<view  v-if="isAccept == true">
				<h3 style="color: #a7a6b0;">&emsp;接受了任务</h3>
				<p style="color: #a7a6b0;">开始：{{new Date(taskInfo.startTime).toLocaleDateString()}}</p>
			</view>
			<view v-if="isAccept == false">
				<br/>
				<h3 style="color: red;">拒绝了任务</h3>
			</view>
		</view>
			<u-cell-group>
					<u-cell-item v-for="item in  taskInfo.classDOList" :key="item.classId" :title="'课程名称：'+item.courseDO.name">
						<view slot="label">
							<p>教师名称：{{item.userDO.name}}</p>
							<p>电&emsp;&emsp;话：{{item.userDO.telephone}}</p>
						</view>
					</u-cell-item>
			</u-cell-group>
			<view v-if="isAccept==null">
				<u-button class="mybtn" @click="saveBindingTeacherToTask" :ripple="true" type="primary">
					开始时间：{{new Date(taskInfo.startTime).toLocaleDateString()}}&emsp;接受
				</u-button>
				<u-button class="mybtn" @click="rejectTask" :ripple="true" type="error">
					拒绝时间：{{new Date(taskInfo.refusedTime).toLocaleDateString()}}&emsp;拒绝
				</u-button>
			</view>
	<u-toast ref="uToast" />
		<drag-button :isDock="true" ></drag-button>
	</view>
</template>

<script>
import dragButton from '../../components/drag-button/drag-button.vue'
	export default {
		components:{dragButton},
		data(){
			return{
				id:null,
				taskInfo:{},
			}
		},
		methods:{
			getTaskNews(){
				this.$u.http.get(`/msg/getTaskNews/${this.id}/${this.user.userId}`).then(res=>{
					if(res.data){
						this.taskInfo = res.data
					}
				})
			},
			/**
			 * 接受任务
			 */
			saveBindingTeacherToTask(){
				let data = {
					"userId":this.user.userId,
					"taskId":this.taskInfo.taskId
				}
				 this.$u.http.post("/task/saveBindingTeacherToTask",this.qs.stringify(data)).then(res=>{
					if(res.data){
						this.$refs.uToast.show({
								title: '接受任务',
								type: 'success',
								//url: '/pages/user/index'
							})
					}
				}) 
			},
			/**
			 * 拒绝任务
			 */
			rejectTask(){
				let data = {
					"userId":this.user.userId,
					"taskId":this.taskInfo.taskId
				}
				this.$u.http.post("/task/rejectTask",this.qs.stringify(data)).then(res=>{
					this.$refs.uToast.show({
							title: '拒绝任务',
							type: 'success',
							//url: '/pages/user/index'
						})
				})
			},
			
		},
		onLoad(val) {
			this.id = val.id
			this.getTaskNews()
		},
		computed:{
			user(){
				return this.$store.state.user
			},
			isAccept(){
				return this.$store.state.isReadTaskList?.find(f=>f.taskId == this.taskInfo.taskId).isAccept
			}
		},
	
	
	}
</script>
<style>
	.myview{
		line-height: 60rpx;
		margin: 10rpx 10rpx 10rpx 10rpx;
		background-color: #f4f4f4;
		padding-left: 10rpx;
		border-radius: 7rpx;
		border-left: 12rpx #e6e6e6 solid;
	}
	.mybtn{
		margin: 20rpx;
	}
</style>
